<!-- 选择负责人 -->
<template>
  <div id="dialog-container">
    <el-button type="primary" plain size="small" @click="dialogVisible = true">选择</el-button>
    <el-dialog v-dialogDrag title="选择负责人" append-to-body :visible.sync="dialogVisible" :before-close="handleClose" :close-on-click-modal="false" width="600px">
      <el-form :model="formData" :inline="true" size="small" label-width="60px">
        <el-form-item label="工号：">
          <el-input v-model="formData.username"></el-input>
        </el-form-item>
        <el-button type="primary" plain size="small" @click="showList">查询</el-button>
      </el-form>
      <el-table ref="multipleTable" :data="tableData" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="50"></el-table-column>
        <el-table-column type="index" align="center" label="序号" width="50"></el-table-column>
        <el-table-column prop="username" label="工号" align="center" width=""></el-table-column>
        <el-table-column prop="name" label="姓名" align="center" width=""></el-table-column>
      </el-table>
      <el-row type="flex" justify="center">
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="pageSizeArr"
          :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="pageTotal"></el-pagination>
      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="choose">确 定</el-button>
        <el-button @click="handleClose">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { getByCondition } from 'service/task';
  export default {
    data() {
      return {
        dialogVisible: false,
        formData: {
          empNo: ''
        },
        currentPage: 1,
        pageSizeArr: [10, 20, 50, 100],
        pageSize: 10,
        pageTotal: 10,
        loading: false,
        tableData: [],
        selectionVal: []
      }
    },
    mounted() {
      this.showList();
    },
    methods: {
      handleClose() {
        this.formData.empNo = '';
        this.$refs.multipleTable.clearSelection();
        this.dialogVisible = false;
      },
      handleSelectionChange(val) {
        for(var i = 0; i < val.length; i++) {
          this.selectionVal.push(val[i].username);
        };
        this.selectionVal = this.selectionVal.filter(function(element,index,self) {
          return self.indexOf(element) === index;
        })
      },
      handleSizeChange(val) {
        this.pageSize = val;
        this.showList();
      },
      handleCurrentChange(val) {
        this.currentPage = val;
        this.showList();
      },
      showList() {
        let prams ={
          username: '',
          mobile: '',
          empNo: this.formData.empNo,
          duty: '',
          pageNumber: this.currentPage,
          pageSize: this.pageSize,
          sort: '',
          order: '',
        }
        this.loading = true;
        getByCondition(prams)
          .then(res => {
            this.tableData = res.data.result.content;
            // this.currentPage = res.data.result.pageable.pageNumber;
            this.pageSize = res.data.result.pageable.pageSize;
            this.pageTotal = res.data.result.totalElements;
            this.loading = false;
          })
      },
      choose() {
        this.$emit('owner', this.selectionVal.join(","));
        this.selectionVal.splice(0, this.selectionVal.length);
        this.dialogVisible = false;
      }
    }
  }

</script>
